package com.cskaoyan._01btyestream.in;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/17 16:09
 **/
/*
读取数据的常规步骤:
1.创建输入流对象
2.read方法读取数据
3.close
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        //1.创建输入流对象
        //FileInputStream in = new FileInputStream(new File("a.txt"));
        FileInputStream in = new FileInputStream("D:\\workspace2\\java48th\\a.txt");

        //2.read方法读取数据

        // read() 读取单个字节 返回值是读取到的字节值 readData表示
        // readSingle(in);

        // read(byte[] b)
        // readMulti(in);

        // read(byte[]b ,int off,int len)
        byte[] bytes = new byte[1024];
        int readCount = in.read(bytes, 2, 3);
        System.out.println(new String(bytes));

        //3.close
        in.close();
    }

    private static void readMulti(FileInputStream in) throws IOException {
        byte[] bytes = new byte[1024];
        int readCount = in.read(bytes);
        System.out.println("readCount = " + readCount);
        // byte[]--->String
        System.out.println(new String(bytes));
    }

    private static void readSingle(FileInputStream in) throws IOException {
        int readData = in.read();
        System.out.println(((char) readData));
        int readData2 = in.read();
        System.out.println(((char) readData2));
        int readData3 = in.read();
        System.out.println(((char) readData3));
        int readData4 = in.read();
        System.out.println(readData4);
    }
}
